package require TclCurl

proc com_getURLtoList { outList url {tmpFolder "./" } } {
	upvar $outList upvaroutList

	set strInter "/"
	set strPrefix "CurlTmp"
	set seed [clock clicks]
	set trimedFolder [string trimright $tmpFolder "/"]
	
	set tmpFile "$trimedFolder$strInter$strPrefix$seed.tmp"

	if { [catch {curl::transfer -errorbuffer errMsg -url $url -file $tmpFile} err] } {
		puts "Error(code: $err):$errMsg---when open URL:$url"
		set err [file delete -force -- $tmpFile]
		return 
	}

	if { [file exists $tmpFile] } {
        	set chan [open $tmpFile]
		set resList ""
        	while {[gets $chan line] >= 0} {
	        	lappend resList $line 
        	}
        	close $chan
		set err [file delete -force -- $tmpFile]
	} else {
		puts "Error when open TMP file: tmp file does not exist"
		return
	}

	set upvaroutList $resList
	return
}
